package com.ruoyi.web.controller.archive;

import com.ruoyi.system.domain.PProductProp;
import com.ruoyi.system.service.IPProductPropService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品属性Controller
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@RestController
@RequestMapping("/archive/productProp")
public class PProductPropController extends BaseController
{
    @Autowired
    private IPProductPropService pProductPropService;

    /**
     * 查询商品属性列表
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:list')")
    @GetMapping("/list")
    public TableDataInfo list(PProductProp pProductProp)
    {
        startPage();
        List<PProductProp> list = pProductPropService.selectPProductPropList(pProductProp);
        return getDataTable(list);
    }

    /**
     * 导出商品属性列表
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:export')")
    @Log(title = "商品属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PProductProp pProductProp)
    {
        List<PProductProp> list = pProductPropService.selectPProductPropList(pProductProp);
        ExcelUtil<PProductProp> util = new ExcelUtil<PProductProp>(PProductProp.class);
        util.exportExcel(response, list, "商品属性数据");
    }

    /**
     * 获取商品属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pProductPropService.selectPProductPropById(id));
    }

    /**
     * 新增商品属性
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:add')")
    @Log(title = "商品属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PProductProp pProductProp)
    {
        return toAjax(pProductPropService.insertPProductProp(pProductProp));
    }

    /**
     * 修改商品属性
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:edit')")
    @Log(title = "商品属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PProductProp pProductProp)
    {
        return toAjax(pProductPropService.updatePProductProp(pProductProp));
    }

    /**
     * 删除商品属性
     */
    @PreAuthorize("@ss.hasPermi('archive:productProp:remove')")
    @Log(title = "商品属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pProductPropService.deletePProductPropByIds(ids));
    }
}
